load("@rules_rust//rust:defs.bzl", "rust_library")
load("//bazel:canisters.bzl", "rust_canister")
load("//bazel:defs.bzl", "rust_ic_test")

package(default_visibility = [
    # Keep sorted.
    "//rs/nervous_system/clients:__pkg__",
    "//rs/nervous_system/common:__subpackages__",
    "//rs/nervous_system/runtime:__pkg__",
    "//rs/nns:__subpackages__",
    "//rs/registry/canister:__pkg__",
    "//rs/rosetta-api/icp:__pkg__",
    "//rs/rust_canisters:__subpackages__",
    "//rs/sns:__subpackages__",
    "//rs/tests:__subpackages__",
])

DEPENDENCIES = [
    # Keep sorted.
    "//packages/ic-http-types",
    "//rs/rust_canisters/dfn_core",
    "//rs/rust_canisters/on_wire",
    "//rs/types/base_types",
    "@crate_index//:candid",
    "@crate_index//:serde",
]

MACRO_DEPENDENCIES = []

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/rust_canisters/canister_test",
]

MACRO_DEV_DEPENDENCIES = []

ALIASES = {}

rust_library(
    name = "dfn_candid",
    srcs = glob(["src/**/*.rs"]),
    aliases = ALIASES,
    crate_name = "dfn_candid",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.9.0",
    deps = DEPENDENCIES,
)

rust_canister(
    name = "candid-test-canister",
    srcs = ["test/wasm.rs"],
    aliases = ALIASES,
    proc_macro_deps = MACRO_DEPENDENCIES,
    service_file = ":test/wasm.did",
    deps = DEPENDENCIES + [":dfn_candid"],
)

rust_ic_test(
    name = "dfn_candid_test",
    srcs = ["test/test.rs"],
    aliases = ALIASES,
    crate_root = "test/test.rs",
    data = [
        ":candid-test-canister",
    ],
    env = {
        "CANDID_TEST_CANISTER_WASM_PATH": "$(rootpath :candid-test-canister)",
    },
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES + ["dfn_candid"],
)
